package com.G_CN06.mvc.service.impl;

import com.G_CN06.commonUtil.CacheGuava;
import com.G_CN06.commonUtil.MD5Utils;
import com.G_CN06.mvc.entity.User;
import com.G_CN06.mvc.mapper.UserMapper;
import com.G_CN06.mvc.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import sun.security.provider.MD5;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Huang
 * @since 2022-11-15
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    UserMapper userMapper;
    @Resource
    CacheGuava cacheGuava;

    @Override
    public User login(String phoneNumber, String password) {
        //登录人查询
        LambdaQueryWrapper<User> wrapper = new QueryWrapper<User>().lambda();
        wrapper.eq(StringUtils.isNotBlank(phoneNumber),User::getPhone,phoneNumber);
        User user = userMapper.selectOne(wrapper);
        //密码验证
        if (user!=null){
            String pw = user.getPassword();
            return pw.equals(MD5Utils.getPwd(password)) ? user : null;
        }
        return null;
    }
}
